package com.example.modellol.Fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.modellol.R;
import com.example.modellol.adapter.MyAdapter2;
import com.example.modellol.bean.News;

import java.util.ArrayList;


public class FirstFragment extends Fragment {


    private View view;
    public RecyclerView mCollectRecyclerView;
    private ArrayList<News> goodsEntityList = new ArrayList<News>();
    private MyAdapter2 mCollectRecyclerAdapter;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.item_recycle, container, false);
        initRecyclerView();
        initData();
        return view;
    }


    int[] c =new int[]{R.drawable.video_1, R.drawable.video_2,
            R.drawable.video_3, R.drawable.video_4,
            R.drawable.video_5, R.drawable.video_6,
            R.drawable.video_7};

    String[] b=new String[]{"13","101","4",
            "3","5",
            "28","12",
    };
    String[] d=new String[]{"LPL春季赛3月11日首发名单，Scout中单交手icon","小蜜蜂宝典专题页面错误更正公告",
            "英雄麦克疯：Zhuo关键一钩，JackeyLove再现一打四","Gen vs T1赛事预热：传统强队的碰撞一触即发",
            "Top5: Karsa毁灭冲锋 单骑成万军","LPL春季赛3月10日首发名单，SofM野区对决Haro",
            "Top5: Mole发条协奏背水终斩敌"
    };



    private void initData() {
        goodsEntityList.clear();
        for(int i=0;i<7;i++){
            News goodsEntity=new News();
            goodsEntity.setText_one(d[i]);
            goodsEntity.setText_two("英雄联盟赛事官方");
            goodsEntity.setText_three(b[i]);
            goodsEntity.setImgPath_one(R.drawable.icon_lol_tb);
            goodsEntity.setImgPath_two(c[i]);
            goodsEntityList.add(goodsEntity);
        }
    }

    private void initRecyclerView() {
        mCollectRecyclerView = (RecyclerView) view.findViewById(R.id.m_recycle);
        mCollectRecyclerAdapter = new MyAdapter2(getActivity(), goodsEntityList);
        mCollectRecyclerView.setAdapter(mCollectRecyclerAdapter);
        mCollectRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        mCollectRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
        mCollectRecyclerAdapter.setOnItemClickListener(new MyAdapter2.OnItemClickListener() {
            @Override
            public void OnItemClick(View view, News data) {
                Toast.makeText(getActivity(), "我是item", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
